<?php

$where_array = array();

$cat_id = intval($cat_id);
$root_id = get_module_root_category_id($cat_id);
$search_title = trim($search_title);

$cat_ids = $category_list[$cat_id]['childids'];
//var_dump(!empty($cat_ids));exit(0);
$page = $page > 0 ? intval($page) : 1;
$per_page = 30;
$row_start = ($page - 1) * $per_page;

$where_array[] = "`status` IN('NEED_GENERATE','GENERATED')";
!empty($cat_ids) && $where_array[] = "`cat_id` IN({$cat_ids})";
!empty($search_title) && $where_array[] = "`product_name` LIKE '%{$search_title}%'" && $parameter = '/search_title/'.urlencode($search_title);

$sql = 'SELECT * FROM `product_list` WHERE '.implode(' AND ', $where_array);

$records = $db->result_first(str_replace('*', 'count(*)', $sql));
$data = $db->fetch_all($sql . " ORDER BY `id` DESC LIMIT {$row_start},{$per_page}");
$total_page = ceil($records/$per_page);
?>
